home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / vgamaze4.zip / SQUARE.CPP < prev    next >
C/C++ Source or Header  |  1994-03-02  |  4KB  |  136 lines

  1. //
  2. //       This program will generate a three dimensional maze on a VGA display.
  3. //  A different random number seed will produce a different maze.
  4. //
  5. //       Written by James L. Dean
  6. //                  406 40th Street
  7. //                  New Orleans, LA 70124-1532
  8. //
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <math.h>
  12. #include <stdlib.h>
  13. #include <conio.h>
  14. #include <time.h>
  15. #include <iostream.h>
  16. #include "oracle.h"
  17. #include "cell.h"
  18. #include "titillat.h"
  19. #include "sqrmaze.h"
  20. #include "plot3d.h"
  21. #include "vga3d.h"
  22.  
  23. #ifndef TRUE
  24. #define TRUE -1
  25. #endif
  26. #ifndef FALSE
  27. #define FALSE 0
  28. #endif
  29.  
  30. // maze constants
  31. #define PIXELS_PER_ROOM 30
  32. #define RESOLUTION       4  // larger values takes more time (and virtual
  33.                             // memory) but produce a better image
  34.  
  35. static int    external_to_plot(double,double);
  36. static double f(double,double);
  37.        int    main(void);
  38. static int    red(double,double);
  39.  
  40. extern unsigned _stklen=0x8000;
  41.        maze     *maze_ptr;
  42.  
  43. int main()
  44.     {
  45.       static   int    fatal_error;
  46.       static   int    num_columns;
  47.       static   int    num_rows;
  48.       static   double light_x;
  49.       static   double light_y;
  50.       static   double light_z;
  51.       static   int    response;
  52.       static   double rotation;
  53.       static   char   seed [9];
  54.                time_t start_time;
  55.                time_t stop_time;
  56.       static   double tilt;
  57.       static   vga3d  *vga3d_ptr;
  58.  
  59.       fatal_error=FALSE;
  60.       clrscr();
  61.       cout << "                                 Maze Generator"
  62.        << '\n' << '\n' << '\n' << '\n';
  63.       cout << "     After the maze is displayed, press \"S\" to see the "
  64.        << "solution or another" << '\n';
  65.       cout << "key to exit.  If the solution is displayed, press any key "
  66.        << "to exit." << '\n';
  67.       cout << "\n     Random number seed? ";
  68.       cin.get(&seed[0],9,'\n');
  69.       time(&start_time);
  70.       stop_time=start_time;
  71.       vga3d_ptr=new vga3d();
  72.       num_columns=(vga3d_ptr->num_x_pixels())/PIXELS_PER_ROOM;
  73.       num_rows=(int) (((2.0/sqrt(3.0))
  74.        *(vga3d_ptr->aspect_ratio())
  75.        *((double) (vga3d_ptr->num_y_pixels())))
  76.        /((double) PIXELS_PER_ROOM));
  77.       maze_ptr=new maze(num_rows,num_columns,RESOLUTION,&seed[0]);
  78.       if (maze_ptr->constructed())
  79.         {
  80.           rotation=(double) 0.0;
  81.           tilt=(double) 30.0;
  82.           light_x=(double) 1.5;
  83.           light_y=(double) -1.0;
  84.           light_z=(double) 2.6;
  85.           if (vga3d_ptr->prepare_plot(f,maze_ptr->x_min(),maze_ptr->x_max(),
  86.            maze_ptr->y_min(),maze_ptr->y_max(),external_to_plot,red,
  87.            maze_ptr->num_x_divisions(),maze_ptr->num_y_divisions(),
  88.            rotation,tilt,light_x,light_y,light_z))
  89.             {
  90.               if (vga3d_ptr->plot("",FALSE,FALSE,1.0))
  91.                 {
  92.                   time(&stop_time);
  93.                   fflush(stdin);
  94.                   response=getch();
  95.                   fflush(stdin);
  96.                   if ((response == (int) 's')
  97.                   ||  (response == (int) 'S'))
  98.                     {
  99.                       if (vga3d_ptr->plot("",TRUE,FALSE,1.0))
  100.                         {
  101.                           fflush(stdin);
  102.                           response=getch();
  103.                           fflush(stdin);
  104.                         }
  105.                     }
  106.                 }
  107.             }
  108.         }
  109.       delete maze_ptr;
  110.       delete vga3d_ptr;
  111.       cout << "     It took " << stop_time-start_time  
  112.        << " seconds to generate and display the maze." << '\n';
  113.       return(fatal_error);
  114.     }
  115.  
  116. static int external_to_plot(
  117.   double x,
  118.   double y)
  119.     {
  120.        return maze_ptr->external_to_maze(x,y);
  121.     }
  122.  
  123. static int red(
  124.   double x,
  125.   double y)
  126.     {
  127.        return maze_ptr->part_of_solution(x,y);
  128.     }
  129.  
  130. static double f(
  131.   double x,
  132.   double y)
  133.     {
  134.        return maze_ptr->f(x,y);
  135.     }
  136.